importClass(java.util.HashSet);
importClass(java.util.List);
importClass(java.util.Map);
importClass(java.util.ArrayList);
importPackage(Packages.org.bukkit);
importPackage(Packages.java.io);
importPackage(Packages.java.awt);
importPackage(Packages.javax.imageio);
importPackage(Packages.com.sk89q.worldedit);
importPackage(Packages.com.sk89q.worldedit.schematic);
importPackage(Packages.com.sk89q.worldedit.blocks);
importPackage(Packages.com.sk89q.worldguard.bukkit);
importPackage(Packages.com.sk89q.worldguard.bukkit.commands);

var sess = context.remember();
/*
var f = new FileReader("saveregions");
var fReader = new BufferedReader(f);
var l;
var savedregions = new ArrayList();
while((l = fReader.readLine()) != null){
  savedregions.add(l);
}
/**/


var format = SchematicFormat.getFormats().iterator().next();
var pl = Bukkit.getPlayer(player.getName());

for(var worlds = Bukkit.getWorlds().iterator(); worlds.hasNext();){
  var w = worlds.next();
  var rm = WGBukkit.getRegionManager(w);
  var regions = rm.getRegions().keySet().toArray();
  for(var rn=0; rn<regions.length; rn++){
    r = rm.getRegion(regions[rn]);
    if(r.volume()<1000000){
      var orig = r.getMinimumPoint();
      var size = r.getMaximumPoint().subtract(orig).add(1,1,1);
      var schemfile = context.getSafeFile("schematics/"+w.getName(),r.getId().replace('/','_')+".schematic");
      if(schemfile.exists()){
//      command = "scload load regions/"+r.getId()+" "+w.getName()+" "+orig.getBlockX()+" "+orig.getBlockY()+" "+orig.getBlockZ();
//      pl.performCommand("/schem load regions/"+r.getId());
//      pl.performCommand("/paste -o");
        player.print(r.getId());
        Bukkit.getLogger().info("loading "+schemfile.getName());
        var clip = format.load(schemfile);
        clip.paste(sess,orig,false,false);
      }
    }
  }
}

